<?php
/**
* @version		$Id: vinaora_item.php 2010-07-15 vinaora $
* @package		VINAORA MP3 PLAYER
* @copyright	Copyright (C) 2010 VINAORA. All rights reserved.
* @license		GNU/GPL
* @website		http://vinaora.com
* @email		admin@vinaora.com
* 
*/

// no direct accessd
defined( '_JEXEC' ) or die( 'Restricted access' );

class modVinaoraMP3PlayerItem
{

	/*
	 * Get List of Items from a Folder
	 */
	function getItems($folder, $root, $default, $filter, $exclude, $fullpath=false){
	
		jimport('joomla.filesystem.folder');
	
		switch($folder){
			case '-1':
				$items = NULL;
				break;

			case '':
				//TODO: Check the folder exits or not
				
				$items =  JFolder::files($default, $filter, false, $fullpath, $exclude);
				break;

			default:
				//TODO: Check the folder exits or not
				
				$items =  JFolder::files($root.DS.$folder, $filter, false, $fullpath, $exclude);
				break;
		}

		return $items;

	}

	/*
	 * Get Item Path
	 */
	function getItemPath($folder, $root='images/stories/', $default=''){
		
		$base_path = modVinaoraMP3PlayerParam::getBasePath();

		switch($folder){
			case '-1':
				$path = NULL;
				break;
			
			case '':
				if (!empty($default)){
					//$path = $default;
					//$path = ($base_path == '/') ? $path : $base_path.$path;
					$path = $base_path.$default;
					break;
				}
				else{
					$path = NULL;
					break;
				}
			
			default:
				//$path = $root.$folder;
				//$path = ($base_path == '/') ? $path : $base_path.$path;
				$path = $base_path.$root.$folder;
				break;
		}
		
		return $path;
		
	}
	
	/*
	 * Get Attributes by Element Path
	 */
	function getAttributes($config, $path, $name = null){

		$node = $config->document;

		if ($node) $node = $node->getElementByPath($path);
		else return;

		if ($node) $attb = $node->attributes($name);
		else return;

		return $attb;
	}

}
